package com.nari.ies.ne.nw.server.service.fileScore.impl;

import com.nari.ies.ne.nw.server.entity.WindFileScoreEntity;
import com.nari.ies.ne.nw.server.mapper.FileScoreMapper;
import com.nari.ies.ne.nw.server.service.fileScore.IFDJZFileScoreService;
import com.nari.ies.ne.nw.server.service.fileScore.IFileScoreService;
import com.nari.ies.ne.nw.server.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class FDJZFileScoreServiceImpl implements IFDJZFileScoreService {
    @Autowired
    private IFileScoreService fileScoreService;
    @Autowired
    private FileScoreMapper fileScoreMapper;

    @Override
    public WindFileScoreEntity FDJZFileScore(WindFileScoreEntity windFileScoreEntity) {
        String plantId = windFileScoreEntity.getPlantId();
        //今天00:00
        Date endDate = windFileScoreEntity.getDateTime();
        Date startDate = DateUtil.getYesterdayTime(endDate);
        String fileType = "FDJZ";
        String plantType = "FD";
        String tableName = "HISDB.NW_NE_FILE_DATACHECK_FD_FDJZ";

        //上送文件数量
        int FDJZNum = fileScoreMapper.selectFileNumData(tableName,plantId, fileType, plantType, startDate, endDate);
        //文件满分
        float FDJZFullScore = fileScoreMapper.selectFileFullScore(fileType, plantType);
        //完整率
        float FDJZRate = 0;
        //文件上送率
        float FDJZSendRate = 0;
        //文件得分
        float FDJZScore = 0;
        //文件合格率
        float FDJZQualifiedRate = 0;

        if (FDJZNum > 0) {
            FDJZSendRate = 100;
            // 完整率
            FDJZRate = (float) FDJZNum / 96 * 100;
            //文件数据项总得分
            float fileDataScore = fileScoreService.getFileDataScore(plantId, fileType, plantType, startDate, endDate,tableName);
            //文件得分
            FDJZScore = fileDataScore ;
            //文件合格率
            FDJZQualifiedRate = FDJZScore / FDJZFullScore * 100;
        }else {
            FDJZRate=0;
            FDJZScore=0;
            FDJZSendRate=0;
            FDJZQualifiedRate=0;
        }
        windFileScoreEntity.setFDJZNum(FDJZNum);
        windFileScoreEntity.setFDJZRate(FDJZRate);
        windFileScoreEntity.setFDJZScore(FDJZScore);
        windFileScoreEntity.setFDJZFullScore(FDJZFullScore);
        windFileScoreEntity.setFDJZSendRate(FDJZSendRate);
        windFileScoreEntity.setFDJZQualifiedRate(FDJZQualifiedRate);

        return windFileScoreEntity;
    }
}
